package com.ucode.crm.service.impl;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ucode.crm.mapper.FollowupRecordMapper;
import com.ucode.crm.mode.FollowupRecord;
import com.ucode.crm.service.FollowupRecordService;
import com.ucode.tool.base.Paginator;
import com.ucode.tool.util.IdentifyUtils;

@Service
public class FollowupRecordServiceImpl implements FollowupRecordService {

    @Autowired
    private FollowupRecordMapper followupRecordMapper;
    
    @Override
    public int insert(FollowupRecord followupRecord) {
        Date now = new Date();
        followupRecord.setId(IdentifyUtils.getDefaultSnowflakeId());
        followupRecord.setCreatedTime(now);
        followupRecord.setUpdatedTime(now);
        return followupRecordMapper.insert(followupRecord);
    }
    
    @Override
    public FollowupRecord findById(Long id) {
        return followupRecordMapper.findById(id);
    }

    @Override
    public List<FollowupRecord> findByIds(List<Long> ids) {
        return followupRecordMapper.findByIds(ids);
    }

    @Override
    public int delete(Long id) {
        return followupRecordMapper.delete(id);
    }

    @Override
    public int batchDelete(List<Long> ids) {
        return followupRecordMapper.batchDelete(ids);
    }

    @Override
    public Paginator<FollowupRecord> queryPage(String keyword, Integer targetType, Long targetId, Long contactsId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<FollowupRecord> list = followupRecordMapper.queryList(keyword, targetType, targetId, contactsId);
        PageInfo<FollowupRecord> pageInfo = new PageInfo<>(list);
        return new Paginator<>(pageInfo.getTotal(), pageInfo.getPageNum(), pageInfo.getPageSize(), list);
    }
    
}
